package com.pctx.registerlogin.controller;

import com.pctx.common.result.Result;
import com.pctx.registerlogin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;


    @RequestMapping("/addDepartment")
    public Result addDepartment(@RequestParam("departmentname") String departmentname, @RequestParam("username") String username) {
        return userService.addDepartment(departmentname, username);
    }

    @RequestMapping("/addPositionone")
    public Result addPositionone(@RequestParam("positionname") String positionname, @RequestParam("departmentuuid") String departmentuuid, @RequestParam("username") String username) {
        return userService.addPositionone(positionname, departmentuuid, username);
    }

    @RequestMapping("/selectDepartment")
    public Result selectDepartment(@RequestParam("username") String username) {
        return userService.selectDepartment(username);
    }

    @RequestMapping("/selectPosition")
    public Result selectPosition(@RequestParam("username") String username, @RequestParam("departmentuuid") String departmentuuid) {
        return userService.selectPosition(username, departmentuuid);
    }

    @RequestMapping("/addUser")
    public Result addUser(@RequestParam("username") String username, @RequestParam("name") String name, @RequestParam("mobile") String mobile, @RequestParam("mail") String mail, @RequestParam("sex") String sex,
                          @RequestParam("departmentuuid") String departmentuuid, @RequestParam("positionuuid") String positionuuid, @RequestParam("upperleader") String upperleader, @RequestParam("subordinate") String subordinate) {
        return userService.addUser(username, name, mobile, mail, sex, departmentuuid, positionuuid, upperleader, subordinate);
    }

    @RequestMapping("/updateUser")
    public Result updateUser(@RequestParam("username") String username, @RequestParam("name") String name, @RequestParam("mobile") String mobile,
                             @RequestParam("mail") String mail, @RequestParam("sex") String sex, @RequestParam("departmentuuid") String departmentuuid,
                             @RequestParam("positionuuid") String positionuuid, @RequestParam("upperleaderuuid") String upperleaderuuid, @RequestParam("subordinate") String subordinate) {
        return userService.updateUser(username, name, mobile, mail, sex, departmentuuid, positionuuid, upperleaderuuid, subordinate);
    }

    @RequestMapping("/hassubordinate")
    public Result hassubordinate(@RequestParam("loginuser") String loginuser) {

        return userService.hassubordinate(loginuser);
    }

    @RequestMapping("/deleteUser")
    public Result deleteUser(@RequestParam("username") String username) {
        return userService.deleteUser(username);
    }

    @RequestMapping("/resetPassword")
    public Result resetPassword(@RequestParam("username") String username) {
        return userService.resetPassword(username);
    }

    @RequestMapping("/personalMessage")
    public Result personalMessage(String username) throws Exception {
    return    userService.personalMessage(username);


    }
}